import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
host_server='smtp.qq.com'
sender='531786847@qq.com'
code='fxqvalyklodxcagb'
user='viscaria@webmail.hzau.edu.cn'
mail_title='邮件发送测试'
mail_content='调用smtplib和email两个包，此邮件为测试，附件为编程训练脚本。'
attachment=MIMEApplication(open('readexcel.py','r').read())
attachment.add_header('Content-Disposition','attachment',filename='test.txt')
smtp=smtplib.SMTP(host_server)
smtp.login(sender,code)
msg=MIMEMultipart()
msg['Subject']=mail_title
msg['From']=sender
msg['To']=user
msg.attach(MIMEText(mail_content))
msg.attach(attachment)
smtp.sendmail(sender,user,msg.as_string())
smtp.quit()
